# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test")

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

cc_library(
    name = "cpu_qos_test",
    testonly = True,
    srcs = [
        "cpu_qos_test.cc",
    ],
    hdrs = [
        "cpu_qos_test.h",
    ],
    deps = [
        ":gnmi_parsers",
        ":packet_in_receiver",
        ":qos_test_util",
        "//gutil/gutil:collections",
        "//gutil/gutil:proto",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//gutil/gutil:version",
        "//lib:ixia_helper",
        "//lib/gnmi:gnmi_helper",
        "//lib/gnmi:openconfig_cc_proto",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi:p4_runtime_session_extras",
        "//p4_pdpi:pd",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:ipv6_address",
        "//p4_pdpi/netaddr:mac_address",
        "//p4_pdpi/packetlib",
        "//p4_pdpi/packetlib:packetlib_cc_proto",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:p4_versions",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "//sai_p4/instantiations/google/test_tools:test_entries",
        "//tests/forwarding:util",
        "//tests/integration/system/nsf:util",
        "//tests/integration/system/nsf/interfaces:testbed",
        "//tests/lib:switch_test_setup_helpers",
        "//tests/sflow:sflow_util",
        "//thinkit:generic_testbed",
        "//thinkit:generic_testbed_fixture",
        "//thinkit:mirror_testbed",
        "//thinkit:mirror_testbed_fixture",
        "//thinkit:ssh_client",
        "//thinkit:switch",
        "//thinkit/proto:generic_testbed_cc_proto",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_proto",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:optional",
        "@com_google_absl//absl/types:variant",
        "@com_google_googletest//:gtest",
        "@com_google_protobuf//:protobuf",
    ],
    alwayslink = True,
)

cc_library(
    name = "punt_qos_test",
    testonly = True,
    srcs = [
        "punt_qos_test.cc",
    ],
    hdrs = [
        "punt_qos_test.h",
    ],
    deps = [
        ":packet_in_receiver",
        ":qos_test_util",
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//lib:ixia_helper",
        "//lib/gnmi:gnmi_helper",
        "//lib/gnmi:openconfig_cc_proto",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:mac_address",
        "//p4_pdpi/packetlib:packetlib_cc_proto",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "//sai_p4/instantiations/google/test_tools:test_entries",
        "//tests/forwarding:util",
        "//tests/gnmi:util",
        "//tests/lib:switch_test_setup_helpers",
        "//thinkit:generic_testbed",
        "//thinkit:generic_testbed_fixture",
        "//thinkit:ssh_client",
        "//thinkit:switch",
        "//thinkit/proto:generic_testbed_cc_proto",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_proto",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:optional",
        "@com_google_googletest//:gtest",
    ],
    alwayslink = True,
)

cc_library(
    name = "pfc_test",
    testonly = True,
    srcs = ["pfc_test.cc"],
    hdrs = ["pfc_test.h"],
    deps = [
        ":qos_test_util",
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//lib:ixia_helper",
        "//lib/gnmi:gnmi_helper",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:mac_address",
        "//p4_pdpi/packetlib:packetlib_cc_proto",
        "//sai_p4/instantiations/google/test_tools:test_entries",
        "//tests/forwarding:util",
        "//tests/lib:switch_test_setup_helpers",
        "//thinkit:generic_testbed",
        "//thinkit:generic_testbed_fixture",
        "//thinkit:ssh_client",
        "//thinkit:switch",
        "//thinkit/proto:generic_testbed_cc_proto",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_absl//absl/time",
        "@com_google_googletest//:gtest",
    ],
    alwayslink = True,
)

cc_library(
    name = "frontpanel_qos_test",
    testonly = True,
    srcs = ["frontpanel_qos_test.cc"],
    hdrs = ["frontpanel_qos_test.h"],
    deps = [
        ":packet_in_receiver",
        ":qos_test_util",
        "//gutil/gutil:collections",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//lib:ixia_helper",
        "//lib:ixia_helper_cc_proto",
        "//lib/gnmi:gnmi_helper",
        "//lib/utils:json_utils",
        "//lib/validator:validator_lib",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi:p4_runtime_session_extras",
        "//p4_pdpi:pd",
        "//p4_pdpi/internal:ordered_map",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:ipv6_address",
        "//p4_pdpi/netaddr:mac_address",
        "//p4_pdpi/packetlib",
        "//p4_pdpi/packetlib:packetlib_cc_proto",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "//sai_p4/instantiations/google/test_tools:test_entries",
        "//tests/forwarding:util",
        "//tests/integration/system/nsf:util",
        "//tests/integration/system/nsf/interfaces:testbed",
        "//tests/lib:switch_test_setup_helpers",
        "//thinkit:generic_testbed",
        "//thinkit:generic_testbed_fixture",
        "//thinkit:mirror_testbed",
        "//thinkit:ssh_client",
        "//thinkit:switch",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:optional",
        "@com_google_googletest//:gtest",
    ],
    alwayslink = True,
)

cc_library(
    name = "gnmi_parsers",
    srcs = ["gnmi_parsers.cc"],
    hdrs = ["gnmi_parsers.h"],
    deps = [
        "//gutil/gutil:proto",
        "//lib/gnmi:openconfig_cc_proto",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:ipv6_address",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

# go/golden-test-with-coverage
cc_test(
    name = "gnmi_parsers_test_runner",
    srcs = ["gnmi_parsers_test_runner.cc"],
    linkstatic = True,
    deps = [
        ":gnmi_parsers",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//p4_pdpi/internal:ordered_map",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_protobuf//:protobuf",
    ],
)

cmd_diff_test(
    name = "gnmi_parsers_test",
    actual_cmd = "$(execpath :gnmi_parsers_test_runner)",
    expected = ":gnmi_parsers_test.expected.output",
    tools = [":gnmi_parsers_test_runner"],
)

cc_library(
    name = "qos_test_util",
    srcs = ["qos_test_util.cc"],
    hdrs = ["qos_test_util.h"],
    deps = [
        ":gnmi_parsers",
        "//gutil/gutil:collections",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//lib/gnmi:gnmi_helper",
        "//lib/gnmi:openconfig_cc_proto",
        "//lib/utils:json_utils",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "//thinkit:mirror_testbed",
        "//thinkit/proto:generic_testbed_cc_proto",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_proto",
        "@com_github_nlohmann_json//:nlohmann_json",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "packet_in_receiver",
    hdrs = ["packet_in_receiver.h"],
    deps = [
        "//p4_pdpi:p4_runtime_session",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
    ],
)
